#include<iostream>  
using namespace std;
#include<string>
#include<unordered_set>
#include<unordered_map>
unordered_set<string> m1;
unordered_set<string> m2;
unordered_map<string, int> cnt;

int n, m;
const int N = 1e5 +10;
// zdl::接下来还需要一个是数组来来存储整个字符串数组
string s[N];

int main()
{
    cin >> n;
    for  (int i = 1; i <= n; i++) 
    {
        string s; cin >> s;
        m1.insert(s);
    }
    cin >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> s[i];
        if (m1.count(s[i])) m2.emplace(s[i]);
    }

    cout << m2.size() << endl;
    // 卧槽，这种特殊情况，直接占了我10分，现在就需要大家仔细烤炉一些情况下的答案了
    if (m2.empty())
    {
        cout << 0 << endl;
        return 0;
    }
    int ret = N;
    
    // 接下来使用滑动窗口来解决这个问题！
    int kind = 0;
    for (int l = 1, r = 1; r <= m && l <= r; r++)
    {
        if (m1.count(s[r]))
        {
            if(++cnt[s[r]] == 1) kind++;
        }
        while (kind == m2.size())
        {
            ret = min(ret, r - l + 1);
            cnt[s[l++]]--;
            if (cnt[s[l - 1]] == 0) kind--;
        }
    }

    cout << ret << endl;
    return 0;
}   
